<template>
    <div>
        <h1>添加页面</h1>
        <table class="table">
            <tbody>
                <tr>
                    <td>房型名称</td>
                    <td><input type="text" v-model="info.name"></td>
                </tr>
                <tr>
                    <td>价格</td>
                    <td><input type="text" v-model="info.moany"></td>
                </tr>
                <tr>
                    <td>数量</td>
                    <td><input type="text" v-model="info.num"></td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" value="1" v-model="info.start">启用
                        <input type="radio" value="0" v-model="info.start">停用
                    </td>
                </tr>
                <tr>
                    <td>房间号</td>
                    <td>
                        <input type="checkbox" value="1" v-model="info.card">101
                        <input type="checkbox" value="2" v-model="info.card">102
                        <input type="checkbox" value="3" v-model="info.card">103
                        <input type="checkbox" value="4" v-model="info.card">104
                        <input type="checkbox" value="5" v-model="info.card">105
                        <input type="checkbox" value="6" v-model="info.card">106
                        <input type="checkbox" value="7" v-model="info.card">107
                        <input type="checkbox" value="8" v-model="info.card">108
                        <input type="checkbox" value="9" v-model="info.card">109
                        <input type="checkbox" value="10" v-model="info.card">110
                        <input type="checkbox" value="11" v-model="info.card">111

                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <button @click="Add">提交</button>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRouter, useRoute } from 'vue-router';

const router = useRouter();
const route = useRoute();
let info :any = reactive({
    Id: route.query.Id,
    name: "",
  moany: "",
  num: "",
  start: "",
  card: [],
  
});

onMounted(() => {
getall(); 
})
const Add = () => {
    if(info.name==""){
        alert("请输入房型名称");
        return; 
    }
    if(info.moany==""){
        alert("请输入价格");
        return; 
    }
    if(info.num==""){
        alert("请输入数量");
        return; 
    }
    if(info.start==""){
        alert("请选择状态");
        return;
    }
    if(info.card.length==0){
        alert("请选择房间号");
        return; 
    }
    info.card = info.card.toString();
 axios({
    url:"/api/House/update",
    method:"put",
    data:info
 }) 
 .then(res=>{
    console.log(res);
  if(res.data.code>0){
    alert("修改失败");
    return;
   
  }
  else{
    alert("修改成功");
    
    
    
  }
 })
.catch(err=>{
    console.log(err);
    
})
}
const getall = () => {
    axios({
        url: '/api/House/fune',
        method: 'get',
        params: { Id: route.query.Id }
    }) 
    .then((res) => {
     imfo.name=res.data.name;
     imfo.moany=res.data.moany;
     imfo.num=res.data.num;
     imfo.start=res.data.start;
     imfo.card=res.data.card;
        console.log(res);
    })
   .catch((err) => {
        console.log(err);
    }); 
   
}
</script>

<style scoped>

</style>